package com.nlx.notes.module.mapper;

import com.nlx.notes.module.entity.FlowYearStatistics;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author nlx
 * @since 2024-12-15
 */
public interface FlowYearStatisticsMapper extends BaseMapper<FlowYearStatistics> {

    @Update(" update flow_year_statistics set expense = expense +#{amount} where id = #{id}")
    void incYearExpenseAmount(Long id, int amount);

    @Update(" update flow_year_statistics set income = income +#{amount} where id = #{id}")
    void incYearIncomeAmount(Long id, int amount);


    @Update(" update flow_year_statistics set year_amount = year_amount - #{amount} where id = #{id}")
    void decYearAmount(@Param("id") Long id, @Param("amount") Integer amount);

    /**
     * 查询用户的所有年份统计数据
     * @param userId 用户ID
     * @return 年份统计数据列表
     */
    @Select("SELECT * FROM flow_year_statistics WHERE user_id = #{userId} and book_id = #{bookId} AND del_flag = 0 ORDER BY year_time desc")
    List<FlowYearStatistics> findAllByUserId(@Param("userId") Long userId, @Param("bookId") Long bookId);
}
